package ${package}{

<#list imports as imp>
import ${imp};
</#list>
<#if type=="REQ">
import game.communication.AbstractRequestMsg;
import laya.net.Socket;
import protocols.MessageCode;
<#elseif type=="RESP">
import game.communication.AbstractResponseMsg;
import protocols.MessageCode;
</#if>
import laya.utils.Byte;
/**
*${desc}
*@auther ${author}
*/
public class ${name} <#if type=="REQ">extends AbstractRequestMsg<#elseif type=="RESP">extends AbstractResponseMsg</#if>
{
<#list properties as pro>
	/**${pro.desc}*/
	public  var <#if pro.ref =="list">${pro.name} : Vector.<${pro.type}>;<#else>${pro.name} : <@ATYPE>${pro.type}</@ATYPE>;</#if>
</#list>
	/**空的构造方法*/
	public function ${name}(){}

<#if type=="RESP" ||type=="BEAN">
	<#if type=="RESP">override </#if>public function readData(data:Byte):void
	{
	<#list properties as pro>
		<#if pro.isif!=true>
			<#if pro.ref =="bean">
			${pro.name}=new ${pro.type}();
			${pro.name}.readData(data);
			<#elseif pro.ref=="list">
			${pro.name} = new Vector.<<@ATYPE>${pro.type}</@ATYPE>>();
			var ${pro.name}Size:int = data.getInt16();
			for(var i:int = 0;i< ${pro.name}Size; i++)
			{
				<#if pro.type?ends_with("Bean")>
				var tempBean:${pro.type} = new ${pro.type}();
				tempBean.readData(data);
				<#else>
				var tempBean:<@ATYPE>${pro.type}</@ATYPE> =data.get<@LTYPE>${pro.type}</@LTYPE>();
				</#if>
				${pro.name}.push(tempBean);
			}
			<#else>
			${pro.name}=data.get<@LTYPE>${pro.type}</@LTYPE>();
			<#list pro.ifs as ifc>
			if(${pro.name} ${ifc.flag} ${ifc.value})
			{
			<#list ifc.properties as p>
				<#if p.ref =="bean">
				${p.name} = new ${p.type}();
				${p.name}.readData(data);
				<#elseif p.ref=="list">
				${p.name} = new Vector.<<@ATYPE>${pro.type}</@ATYPE>>();
				var ${p.name}Size:int = data.getInt16();
				for(var j:int = 0;j< ${pro.name}Size; j++)
				{
					<#if p.type?ends_with("Bean")>
					var tempBean:${p.type} = new ${p.type}();
					tempBean.readData(data);
					<#else>
					var tempBean:<@ATYPE>${pro.type}</@ATYPE> =data.get<@LTYPE>${pro.type}</@LTYPE>();
					</#if>
					${p.name}.push(tempBean);
				}
				<#else>
				${p.name}=data.get<@LTYPE>${p.type}</@LTYPE>();
				</#if>
			</#list>
			}
			</#list>
			</#if>
		<#else>

		</#if>
	</#list>
	}
</#if>

	<#if type=="REQ" ||type=="BEAN">
	<#if type=="REQ">override </#if>public function writeData(<#if type=="BEAN">data:Byte</#if>):void
	{
		<#if type=="REQ">
		data = new Byte();
		data.endian = Socket.BIG_ENDIAN;
		data.writeInt16(getMsgCode());
		</#if>
	<#list properties as pro>
		<#if pro.isif!=true>
			<#if pro.ref =="bean">
				${pro.name}.writeData(data);
			<#elseif pro.ref=="list">
				data.writeInt16(${pro.name}.length);
				for each(var tempBean:<@ATYPE>${pro.type}</@ATYPE> in ${pro.name})
				{
				<#if pro.type?ends_with("Bean")>
					tempBean.writeData(data);
				<#elseif pro.type=="boolean">
					data.write<@LTYPE>${pro.type}</@LTYPE>(Number(tempBean));
				<#else>
					data.write<@LTYPE>${pro.type}</@LTYPE>(tempBean);
				</#if>
				}
			<#elseif pro.type=="boolean">
				data.write<@LTYPE>${pro.type}</@LTYPE>(Number(${pro.name}));
			<#else>
				data.write<@LTYPE>${pro.type}</@LTYPE>(${pro.name});
			<#list pro.ifs as ifc>
				if(${pro.name} ${ifc.flag} ${ifc.value})
				{
				<#list ifc.properties as p>
					<#if p.ref =="bean">
						${p.name}.writeData(data);
						<#elseif p.ref=="list">
						data.writeInt16((short)${p.name}.Count);
						for each(var tempBean:<@ATYPE>${p.type}</@ATYPE> in ${p.name})
						{
						<#if p.type?ends_with("Bean")>
							tempBean.writeData(data);
							<#else>
								data.write<@LTYPE>${p.type}</@LTYPE>(tempBean);
						</#if>
						}
						<#else>
							data.write<@LTYPE>${p.type}</@LTYPE>(${p.name});
					</#if>
				</#list>
				}
				</#list>
			</#if>
		</#if>
	</#list>
	}
	</#if>

	<#if type!="BEAN">
	override public function getMsgCode():int
	{
		return MessageCode.${conName};
	}
	</#if>

	<#if type=="RESP" || type=="REQ">
	override public function toString():String
	{
		return "${name}["+<#list properties as pro>", ${pro.name}:"+${pro.name}+</#list>"]";
	}
	</#if>
}
}